﻿using Autofac;
using MgSoft.Import.Exchange.ExWebApi.Db.Daos;
using MgSoft.Import.Exchange.ExWebApi.Db.Dtos;
using System;
using System.Collections.Generic;
using System.Text;

namespace MgSoft.Import.Exchange.ExWebApi.Db
{
    public abstract class SouceExWebApiTaskManager<TDto, TDao> : ExWebApiTaskManager<TDto, IDbTask, TDao>
        where TDto : class, IDbExchangeDto
        where TDao : IExchangeDao

    {
        public SouceExWebApiTaskManager(ILifetimeScope lifetimeScope) : base(lifetimeScope)
        {
        }

        protected override void DoAction(object obj)
        {
            try
            {
                var dto = obj as TDto;
                dto.SetDto_BillType(this.BillType);
                dto.SetDto_BillTypeName(this.BillTypeName);                
            }
            catch (Exception ex)
            {
                log.Error($"SouceExWebApiTaskManager基类错误：错误信息【{ex.Message}】\r\n错误栈:【{ex.StackTrace}】");
            }
            finally
            {
                base.DoAction(obj);
            }
        }

        /// <summary>
        /// 业务类型，默认Title，注：Source与Target的业务类型必须一致
        /// </summary>
        protected virtual string BillType => Title;

        /// <summary>
        /// 业务类型名称，默认Title
        /// </summary>
        protected virtual string BillTypeName => Title;
    }
}
